require( '../../../../config' );
var pointhistoryDao = require( '../../../../../app/components/backend/db').pointhistory,
    pointhistoryModel = require( '../../../../../app/components/backend/db/models/pointhistory'),
    assert = require('assert'),
    helper = require('../../../../helper'),
    testData = {
      triggered_by: "oNaHXsspWthiBKBda-E5C_OBP_ao",
      triggered_by_name: "Neil Zeng",
      action_type: 'subscribe_via_qrcode',
      awarded_to: "XXXXXXXXWthiBKBda-E5C_OBP_ao",
      awarded_to_name: "Big Dian",
      create_time: 1447746563585,
      point: 10
    };

describe('app/components/backend/db/models/pointhistory', function() {

  // 测试后置处理
  afterEach(function() {

    // 清空 collection
    pointhistoryModel.remove({}, function(err) {
      if (err) throw new Error(err);
      console.log('\n>>>>>>>>>> collection removed');
    });
  });
  it('[pointhistory.save.Nor.01].保存', function() {

    var insertPromise = pointhistoryDao.insert(testData);
    helper.isBluebirdPromise(insertPromise);
    return insertPromise.then(function (result) {
      assert.equal(testData.triggered_by, result.triggered_by);
      assert.equal(testData.point, result.point);
      return Promise.resolve();
    });
  });
});